package com.armrest.screen.provider

import android.widget.*
import com.armrest.screen.HomeMenuModel
import com.armrest.screen.ItemViewType
import com.armrest.screen.R
import com.armrest.screen.setMediaPlayer
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class BlastProvider(
    var layout: Int = R.layout.blast_home_layout, var itemViewTypes:
    Int = ItemViewType.ITEM_TYPE_GRAVITY_MODEL
) : BaseItemProvider<HomeMenuModel>() {
    override val itemViewType: Int
        get() = itemViewTypes
    override val layoutId: Int
        get() = layout
    var itemClick: ((position: Int) -> Unit)? = null
    var volume: Int = 1
    private var volumeBoolean: Boolean = true
    override fun convert(helper: BaseViewHolder, item: HomeMenuModel) {
        val volumeLl = helper.getViewOrNull<RelativeLayout>(R.id.volume_ll)
        val volumeImg = helper.getViewOrNull<ImageView>(R.id.volume_img)
        val volumeOff = helper.getViewOrNull<ImageView>(R.id.volume_off)
        val progressBar = helper.getViewOrNull<ProgressBar>(R.id.progressBar)
        volumeLl?.let {
            volumeLl.setOnClickListener {
                it.setMediaPlayer()
                if(volumeBoolean){
                    if(1 == volume ||2 == volume ||3 == volume){
                        volume += 1
                    }
                    if(3 == volume){
                       volumeBoolean = false
                    }
                }else if(1 == volume || 2 == volume ||3 == volume){
                    volume -= 1
                    volumeBoolean = 1 == volume
                }
                volumeOff?.setImageResource(
                    when (volume) {
                        1 -> R.mipmap.thermometer_min
                        2 -> R.mipmap.thermometer_one_text
                        else -> R.mipmap.text_f_max_wat_image
                    }
                )
                 val icon= when (volume) {
                     3-> R.mipmap.icon_wind_max
                     2 -> R.mipmap.icon_wind_one
                     else -> R.mipmap.icon_wind_min
                 }
                volumeImg?.setImageResource(icon)
                progressBar?.progress=(volume * 34)
                itemClick?.invoke(volume)
            }
        }
    }
}